/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package slsBeans;

import EL.*;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Tian
 */
@Stateless
public class TableTypeBLO implements TableTypeBLORemote {
    
    @PersistenceContext(unitName = "Tunga_EJB3PU")
    private EntityManager em;

    public List<TableTypes> getAll()
    {
        String hql = "FROM TableTypes";
        Query query = this.em.createQuery(hql);
        List<TableTypes> tableTypes = query.getResultList();
        return tableTypes;
    }

    public TableTypes getByID(int id)
    {
        TableTypes tableType = this.em.find(TableTypes.class, id);
        return tableType;
    }

    public boolean add(TableTypes tableType)
    {
        try
        {
            this.em.persist(tableType);
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
    }

    public boolean edit(TableTypes tableType)
    {
        try
        {
            this.em.merge(tableType);
            return true;
        }
        catch (Exception e)
        {
            return false;
        }
        
    }

    public boolean delete(int id)
    {
        TableTypes tableType = this.getByID(id);
        if(tableType != null)
        {
            try
            {
                this.em.remove(tableType);
                return true;
            }
            catch (Exception e)
            {
                    return false;
            }
        }
        return false;
    }

}
